//
//  EJSMineToolTableViewCell.m
//  ManShiGuang
//
//  Created by 海丰丛 on 2020/1/1.
//  Copyright © 2020 lifayu. All rights reserved.
//

#import "EJSMineToolTableViewCell.h"
#import "EJSMineInfoTableViewCell.h"
#import "EJSMineToolModel.h"

@implementation EJSMineToolTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self initUI];
}

- (void)initUI {
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"EJSMineInfoTableViewCell" bundle:nil] forCellReuseIdentifier:@"EJSMineInfoTableViewCell"];
    
}

- (void)setListModel:(EJSMineToolListModel *)listModel {
    _listModel = listModel;
    [self.tableView reloadData];
}

#pragma mark - tableViewDelegate DataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.listModel.items.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    EJSMineInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EJSMineInfoTableViewCell"];
    EJSMineToolModel *info = [self.listModel.items objectAtIndex:indexPath.row];
    cell.infoImageView.image = [UIImage imageNamed:info.itemImageName];
    cell.titleLabel.text = info.itemTitle;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if ([self.delegate respondsToSelector:@selector(mineToolTableViewDidClickTool:)]) {
        [self.delegate mineToolTableViewDidClickTool:[NSIndexPath indexPathForRow:indexPath.row inSection:[self.listModel.title integerValue]]];
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
